/*
 *     This file is part of Mobile GPS Logger.
 * 
 *     Mobile GPS Logger is free software: you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation, either version 3 of the
 *     License, or (at your option) any later version.
 * 
 *     Mobile GPS Logger is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License v3 for more details.
 * 
 *     You should have received a copy of the GNU General Public License v3
 *     along with Mobile GPS Logger. If not, see <http://www.gnu.org/licenses/>.
*/


package cx.ath.skyflyer.chart;

import javax.microedition.lcdui.Graphics;

/**
 *
 * @author Ahti Legonkov
 */
public class ChartArea {

    public ChartArea(Rectangle chartRect, int horizontalTicks, int verticalTicks) {
        this.chartRect = chartRect;
        this.horizontalTicks = horizontalTicks;
        this.verticalTicks = verticalTicks;
    }

    public void draw(Graphics g) {

        g.setColor(225, 225, 225);
        g.setStrokeStyle(Graphics.DOTTED);

        final int stepX = chartRect.width() / horizontalTicks;
        final int stepY = chartRect.height() / verticalTicks;

        // vertical lines
        for (int i = 1; i <= horizontalTicks; ++i) {
            final int x = chartRect.left + i * stepX;

            g.drawLine(x, chartRect.top, x, chartRect.bottom);
        }

        // horizontal lines
        for (int i = 1; i <= verticalTicks; ++i) {
            final int y = chartRect.bottom - i * stepY;

            g.drawLine(chartRect.left, y, chartRect.right, y);
        }
    }

    private Rectangle chartRect;
    private final int horizontalTicks;
    private final int verticalTicks;
}
